package com.whmskj.xjlhsc.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.whmskj.xjlhsc.controller.vo.EfficiencyVo;
import com.whmskj.xjlhbc.core.AjaxResult;
import com.whmskj.xjlhsc.controller.vo.Result;
import com.whmskj.xjlhsc.service.ScKbService;
import com.whmskj.xjlhsc.service.dto.GroupEfficiencyVo;
import com.whmskj.xjlhsc.service.dto.MaintenanceDataDTO;
import com.whmskj.xjlhsc.service.dto.MaintenanceRecordDTO;
import com.whmskj.xjlhsc.service.dto.StatusCountDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import java.util.List;

/**
 * 看板
 */
@SaIgnore
@RestController
@RequestMapping("/api")
public class ScKbController {

    @Autowired
    private ScKbService service;


    //前纺看板
    @GetMapping("/qfkb/get1")
    public AjaxResult qfkbGet1() {
        Object result = service.qfkbGet1();
        return AjaxResult.success(result);
    }

    // 状态统计
    @GetMapping("/status/count")
    public AjaxResult getStatusCount() {
        StatusCountDTO statusCount = service.getStatusCount();
        return AjaxResult.success(statusCount);
    }

    /**
     * 设备效率
     * @return
     */
    @GetMapping("/efficiency")
    public AjaxResult getEqumentEfficiency(){
        EfficiencyVo vo = service.getEqumentEfficiency();
        return AjaxResult.success(vo);
    }

    /**
     * 班组效率
     * @return
     */
    @GetMapping("/group/efficiency")
    public AjaxResult getShiftProcessEfficiency(
            @RequestParam("startDate") String startDate,
            @RequestParam("endDate") String endDate) {

        try {
            GroupEfficiencyVo result = service.getGroupProcessEfficiency(startDate, endDate);
            return AjaxResult.success(result);
        } catch (Exception e) {
            return AjaxResult.error("获取效率数据失败: " + e.getMessage());
        }
    }

    /**
     * 维保计划
     * @return
     */
    @GetMapping("/wbPlan/list")
    public AjaxResult getMaintenanceRecords(){
        List<MaintenanceRecordDTO> records = service.getMaintenanceRecords();
        return AjaxResult.success(records);
    }

    /**
     * 按日统计维保数据
     * @return
     */
    @GetMapping("/daily")
    public AjaxResult getDailyStats() {
        try {
            List<MaintenanceDataDTO> stats = service.getDailyStats();
            return AjaxResult.success(stats);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("按日统计维保数据失败: " + e.getMessage());
        }
    }

    /**
     * 按月统计维保数据
     * @return
     */
    @GetMapping("/monthly")
    public AjaxResult getMonthlyStats() {
        try {
            List<MaintenanceDataDTO> stats = service.getMonthlyStats();
            return AjaxResult.success(stats);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("按月统计维保数据失败: " + e.getMessage());
        }
    }

    /**
     * 按年统计维保数据
     * @return
     */
    @GetMapping("/yearly")
    public AjaxResult getYearlyStats() {
        try {
            List<MaintenanceDataDTO> stats = service.getYearlyStats();
            return AjaxResult.success(stats);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("按年统计维保数据失败: " + e.getMessage());
        }
    }




    //前纺看板-月机台排名
    @GetMapping("/qfkb/get2")
    public AjaxResult qfkbGet2() {
        Object result = service.qfkbGet2();
        return AjaxResult.success(result);
    }
    //前纺看板-生产状态
    @GetMapping("/qfkb/get3")
    public AjaxResult qfkbGet3() {
        Object result = service.qfkbGet3();
        return AjaxResult.success(result);
    }

    //细纱/络筒看板
    @GetMapping("/hfkb/get1")
    public AjaxResult hfkbGet1(@RequestParam(defaultValue = "细纱") String process) {
        Object result = service.hfkbGet1(process);
        return AjaxResult.success(result);
    }




}
